package cn.hlyc.controller;


import cn.hlyc.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@AllArgsConstructor
public class OrderController {

    private RestTemplate restTemplate;

    @GetMapping("getUser/{id}")
    @HystrixCommand(fallbackMethod = "getUserFallbackMethod")
    public User getUser(@PathVariable("id") Long userId){
        //应该发请求到user的controller  拿到用户的信息
        //User user = restTemplate.getForObject("http://localhost:10020/getUserById/" + userId, User.class);
        User user = restTemplate.getForObject("http://user-service/getUserById/" + userId, User.class);
        return user;
    }

    public User getUserFallbackMethod(@PathVariable("id") Long userId){

        return new User(2L,"ribbon","降级");
    }
}



















